<template>
  <div class="app-container">
    <el-form ref="filterForm" :inline="true" :model="listQuery" class="filter-container">
      <!-- <el-form-item>
        <el-button
          size="small"
          icon="el-icon-download"
          @click="exportSchedule"
        >导出模板文件</el-button>
      </el-form-item>
      <el-form-item>
        <el-upload
          ref="uploadSchedule"
          action=""
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :auto-upload="false"
        >
          <el-button
            size="small"
            icon="el-icon-upload2"
          >选择文件导入</el-button>
          <el-button
            size="small"
            type="success"
            plain
            @click="uploadSchedule"
          >上传</el-button>
          <div slot="tip" class="el-upload__tip">请上传xlsx文件</div>
        </el-upload>
      </el-form-item> -->

      <el-form-item>
        <el-button
          size="small"
          type="success"
          icon="el-icon-plus"
          @click="toScheduleNew"
        >添加医生行程</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      stripe
      fit
      highlight-current-row
    >
      <el-table-column label="ID" width="80" align="center">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="医生姓名">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="医院">
        <template slot-scope="scope">
          {{ scope.row.hospital }}
        </template>
      </el-table-column>
      <el-table-column label="科室">
        <template slot-scope="scope">
          {{ scope.row.department }}
        </template>
      </el-table-column>
      <el-table-column label="职称" align="center">
        <template slot-scope="scope">
          <el-tag
            v-if="!_.isEmpty(scope.row.rank)"
            effect="plain"
            size="mini"
          >{{ scope.row.rank }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="代表">
        <template slot-scope="scope">
          {{ scope.row.company }}
        </template>
      </el-table-column>
      <el-table-column label="角色" align="center">
        <template slot-scope="scope">
          <el-tag
            v-if="!_.isEmpty(scope.row.role)"
            effect="plain"
            size="mini"
          >{{ scope.row.role }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="医生状态">
        <template slot-scope="scope">
          {{ scope.row.status }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="出行和住宿">
        <template slot-scope="scope">
          {{ scope.row.company }}
        </template>
      </el-table-column> -->
      <el-table-column label="已查阅出行和住宿信息" align="center">
        <template slot-scope="scope">
          <i v-if="scope.row.isRead === 1" class="el-icon-check text-success" />
          <i v-else class="el-icon-close text-warning" />
        </template>
      </el-table-column>
      <el-table-column label="已设置推送任务" align="center">
        <template slot-scope="scope">
          <i v-if="scope.row.isPush === 1" class="el-icon-check text-success" />
          <i v-else class="el-icon-close text-warning" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope">
          <el-dropdown trigger="click">
            <el-button
              size="mini"
              plain
            >操作 <i class="el-icon-arrow-down el-icon--right" /></el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                @click.native="toScheduleShow(scope.row.id)"
              >查看行程</el-dropdown-item>
              <el-dropdown-item
                @click.native="toScheduleEdit(scope.row.id)"
              >编辑行程</el-dropdown-item>
              <el-dropdown-item
                @click.native="pushSchedule(scope.row.userId, scope.row.id)"
              >行程推送</el-dropdown-item>
              <el-dropdown-item
                divided
                @click.native="removeSchedule(scope.row.id)"
              >
                <span class="text-danger">删除行程</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="fetchData" /> -->
  </div>
</template>

<script>
import {
  getMeetingSchedule,
  pushMeetingSchedule,
  // exportMeetingSchedule,
  // uploadMeetingSchedule,
  removeMeetingSchedule
} from '@/api/meetings'
// import Pagination from '@/components/Pagination'

export default {
  name: 'MeetingScheduleList',
  // components: {
  //   Pagination
  // },
  props: {
    meetingId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      listQuery: {
        meetingId: this.meetingId
        // page: 1,
        // size: 10
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // exportSchedule() {
    //   exportMeetingSchedule().then(response => {
    //     // console.log(response)
    //   }).catch(err => {
    //     console.log(err)
    //   })
    // },
    // uploadSchedule() {
    //   uploadMeetingSchedule().then(response => {
    //     // console.log(response)
    //   }).catch(err => {
    //     console.log(err)
    //   })
    // },
    // handleRemove(file, fileList) {
    //   console.log(file, fileList);
    // },
    // handlePreview(file) {
    //   console.log(file);
    // },
    pushSchedule(userId, id) {
      pushMeetingSchedule({
        meetingId: this.meetingId,
        userId,
        id
      }).then(response => {
        // console.log(response)
        if (response.rtncode === 200) {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '推送成功!'
          })
        } else {
          this.$message({
            type: 'info',
            message: '推送失败，请稍后再试'
          })
        }
      }).catch(err => {
        console.log(err)
      })
    },
    fetchData() {
      this.listLoading = true
      getMeetingSchedule(this.listQuery).then(response => {
        // console.log(response)
        this.list = response.data
        this.total = response.total
        this.listLoading = false
      }).catch(err => {
        console.log(err)
      })
    },
    removeSchedule(id) {
      this.$confirm('此操作将永久删除该行程, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeMeetingSchedule({ id }).then(response => {
          // console.log(response)
          this.fetchData()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    toScheduleNew() {
      this.$router.push(`/meetings/list/${this.meetingId}/schedule/new`)
    },
    toScheduleShow(id) {
      this.$router.push(`/meetings/list/${this.meetingId}/schedule/${id}`)
    },
    toScheduleEdit(id) {
      this.$router.push(`/meetings/list/${this.meetingId}/schedule/${id}/edit`)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-upload__tip {
  line-height: normal;
}
</style>
